package com.wongoing.apiclient.weixin;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import com.wongoing.bus.util.Constants;

public class WXPayConfigImpl extends WXPayConfig{
	
    private byte[] certData;
    private static WXPayConfigImpl INSTANCE;

    private WXPayConfigImpl() throws Exception{
        String certPath = Thread.currentThread().getContextClassLoader().getResource("").getPath()+"apiclient_cert.p12";
    	//String certPath = "D:\\common\\apiclient_cert.p12";
    	File file = new File(certPath);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }

    public static WXPayConfigImpl getInstance() throws Exception{
        if (INSTANCE == null) {
            synchronized (WXPayConfigImpl.class) {
                if (INSTANCE == null) {
                    INSTANCE = new WXPayConfigImpl();
                }
            }
        }
        return INSTANCE;
    }

    public String getAppID() {
    	return Constants.WEBCHAT_PUB_APPID;
    }

    public String getMchID() {
    	return Constants.WEBCHAT_MCH_ID;
    }

    public String getKey() {
    	return Constants.WEBCHAT_MCH_KEY;
    }

    public InputStream getCertStream()   {
        ByteArrayInputStream certBis;
        certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }


    public int getHttpConnectTimeoutMs() {
        return 2000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    IWXPayDomain getWXPayDomain() {
        return WXPayDomainSimpleImpl.instance();
    }

    public String getPrimaryDomain() {
        return "api.mch.weixin.qq.com";
    }

    public String getAlternateDomain() {
        return "api2.mch.weixin.qq.com";
    }

    @Override
    public int getReportWorkerNum() {
        return 1;
    }

    @Override
    public int getReportBatchSize() {
        return 2;
    }
    
    public String getNotifyUrl() {
    	return Constants.WEBCHAT_NOTIFY_URL;
    }
    
    public String getReferer() {
    	return Constants.WEBCHAT_REFERER;
    }

	public String getTradeTypeNative() {
		return Constants.WEBCHAT_TRADE_TYPE_NATIVE;
	}

	public String getTradeTypeJSAPI() {
		return Constants.WEBCHAT_TRADE_TYPE_JSAPI;
	}

	public String getTradeTypeMWEB() {
		return Constants.WEBCHAT_TRADE_TYPE_MWEB;
	}

	public String getDeviceInfo() {
		return Constants.WEBCHAT_DEVICE_INFO;
	}

	public String getFeeType() {
		return Constants.WEBCHAT_FEE_TYPE;
	}
    
}
